package com.bestpay.demo2.task.aopconfig;

import com.bestpay.drip.commons.annotation.AppInfoManager;
import com.bestpay.drip.commons.exception.ExceptionAdvice;
import com.bestpay.drip.commons.exception.ExceptionConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 全局统一异常AOP的Bean配置类
 */
@Configuration
public class ExceptionAdviceConfiguration {

    private static final String MY_APPLIACATION_PACKAGE = "com.bestpay.demo2";

    /**
     * 注册ExceptionAdvice Bean到Spring容器。<br/>
     * 使用无参的类型转换器，自动pick-up本应用的4位应用编码app_code
     *
     * @return ExceptionAdvice
     */
    @Bean
    public ExceptionAdvice exceptionAdvice() {
        ExceptionConverter appCodeExceptionConverter = new ExceptionConverter(AppInfoManager.getAppCode(),
                MY_APPLIACATION_PACKAGE);
        return new ExceptionAdvice(appCodeExceptionConverter);
    }

}
